package com.nowc.week.w107_ak;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class b {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        solve();
        out.flush();
        out.close();
        br.close();
    }

    static void solve() throws IOException {
         String[] in = br.readLine().split(" ");
         int n = Integer.parseInt(in[0]);
         in = br.readLine().split(" ");
         int[] a = new int[n * 2];
         int[][] b = new int[n + 1][2];
         for (int i = 0; i < n * 2; i++) {
             a[i] = Integer.parseInt(in[i]);
             if (b[a[i]][0] == 0) {
                 b[a[i]][0] = i;
             } else {
                 b[a[i]][1] = i;
             }
         }
         int ans = 0;
         for (int[] x : b) {
             if (x[0] == 0) continue;
             ans = Math.max(ans, Math.abs(x[1] - x[0]) + 1);
         }
        out.println(ans);
    }
}
